package com.article.service.Impl;

import com.article.entity.dto.AdminDao;
import com.article.entity.dto.AdminSearchDao;
import com.article.entity.pojo.Admin;
import com.article.entity.vo.AdminVo;
import com.article.mapper.AdminMapper;
import com.article.service.AdminService;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public AdminVo getAdminPage(AdminSearchDao adminSearchDao) {
        List<Admin> admin = adminMapper.getAdminPage(adminSearchDao);
        AdminVo adminPage = new AdminVo();
        adminPage.setList(admin);
        adminPage.setTotal(adminMapper.getAdminPageCount(adminSearchDao.getSearch()));
        return adminPage;
    }

    @Override
    public boolean addAdmin(AdminDao adminDao) {
        adminDao.setTimes(LocalDate.now());
        return adminMapper.addAdmin(adminDao) > 0;
    }

    @Override
    public boolean updateAdmin(AdminDao adminDao) {
        adminDao.setTimes(LocalDate.now());
        return adminMapper.updateAdmin(adminDao) > 0;
    }

    @Override
    public boolean deleteAdmin(Integer id) {
        return adminMapper.deleteAdmin(id) > 0;
    }

    @Override
    public boolean deleteAdmins(Integer[] ids) {
        return adminMapper.deleteBatchIds(Arrays.asList(ids)) > 0;
    }


}
